//package com.ruoyi.ai.controller;
//
//import com.ruoyi.ai.domain.vo.WxChatVo;
//import com.ruoyi.ai.factory.ModelChatService;
//import com.ruoyi.ai.factory.ModelChatStrategyFactory;
//import com.ruoyi.common.core.domain.R;
//import io.github.lnyocly.ai4j.platform.openai.chat.entity.ChatCompletion;
//import io.github.lnyocly.ai4j.platform.openai.chat.entity.ChatCompletionResponse;
//import io.github.lnyocly.ai4j.platform.openai.chat.entity.ChatMessage;
//import io.github.lnyocly.ai4j.platform.openai.chat.entity.Choice;
//import io.github.lnyocly.ai4j.service.IChatService;
//import io.github.lnyocly.ai4j.service.PlatformType;
//import io.github.lnyocly.ai4j.service.factor.AiService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.util.ArrayList;
//import java.util.List;
//
//@RestController
//@RequestMapping("/open/test")
//public class OpenTestController {
//    // 注入Ai服务
//    @Autowired
//    private  AiService aiService;
//    @GetMapping("/testChat1")
//    public R testChat1(String message) {
//        // 获取chat服务实例
//        IChatService chatService = aiService.getChatService(PlatformType.OLLAMA);
//
//        // 构建请求参数
//        ChatCompletion chatCompletion = ChatCompletion.builder()
//            .model("deepseek-r1:8b")
//            .message(ChatMessage.withUser("鲁迅为什么打周树人"))
//            .build();
//
//        // 发送对话请求
//        ChatCompletionResponse response = null;
//        try {
//            response = chatService.chatCompletion(chatCompletion);
//        } catch (Exception e) {
//            throw new RuntimeException(e);
//        }
//        String returnMsg = null;
//        for (Choice choice : response.getChoices()) {
//            System.out.println(choice.getMessage().getContent());
//            returnMsg = choice.getMessage().getContent().getText();
//        }
//        System.out.println(returnMsg);
//        return R.ok(returnMsg);
//    }
//
//    @GetMapping("/testChatStream")
//    public R testChatStream(String message) {
//        List<WxChatVo> chatVoList = new ArrayList<>();
//        WxChatVo wxChatVo = new WxChatVo();
//        wxChatVo.setRole("user");
//        wxChatVo.setContent(message);
//        chatVoList.add(wxChatVo);
//        ModelChatService modelChatService = ModelChatStrategyFactory.getEnableMfg();
//        String answer = modelChatService.chatStream(chatVoList, 0L);
//        return R.ok(answer);
//    }
//}
